#!/usr/bin/env python
# encoding: utf-8
# @author: liusir
# @file: demo_07.py
# @time: 2022/11/13 3:04 PM

import json

# key对比
str_01 = '{"access_token":"ACCESS_TOKEN","expires_in":7200}'
json_obj = json.loads( str_01 )
if "access_token" in json_obj.keys(): # 单个key
    print( True )
else:
    print( False )

check_keys = ["access_token","expires_in"]
yes_no = []
for check_key in check_keys:
    if check_key in json_obj.keys():
        yes_no.append( True )
    else:
        yes_no.append( False )
if False in yes_no:
    print( False )

# key_value断言
str_02 = '{"access_token":"123","expires_in":7200}'
check_data = '{"expires_in":7200}'
json_obj_02 = json.loads( str_02 )
json_obj_check_data = json.loads(check_data)
print( list(json_obj_02.items()) )
print( list(json_obj_check_data.items()) )
if list(json_obj_check_data.items())[0] in list(json_obj_02.items()):
    print( True )
else:
    print( False )

check_datas = '{"access_token":"1234","expires_in":7200}'
json_obj_check_datas = json.loads(check_datas)
yes_no = []
for json_obj_check_data in json_obj_check_datas.items():
    if json_obj_check_data in json_obj_02.items():
        yes_no.append( True )
    else:
        yes_no.append( False )
if False in yes_no:
    print( False )
print('**************************')
import re
# 正则断言
str_02 = '{"access_token":"123","expires_in":7200}'
check_data = '"access_token":"(.+?)"'
v = re.findall( check_data ,  str_02)
if v:
    print(True)
else:
    print(False)
